<?php

class address_model extends Model
{	
	public $address_id;
	public $address;
	public $city ;
	public $district;
	public $state;
	public $pin;
	public $phone;
	public $mob;
	
	
	
	public function __construct() 
	{
		parent::Model();
	}

	public function getAll()
	{
		$query = $this->db->get('address');
		return $query->result();
	}
	
	public function getById($address_id) 
	{
		$query = $this->db->get_where('address', array('address_id' => $address_id));
		return $query->row();
	}

	private function insert($post) 
	{
	
		return $this->db->insert('address', $this);
	}
	
	private function update($post) 
	{
	
		$this->db->set('address', $this->address);
		$this->db->set('city', $this->city);
		$this->db->set('district', $this->district);
		$this->db->set('state', $this->state);
		$this->db->set('pin', $this->pin);
		$this->db->set('phone', $this->phone);
		$this->db->set('mob', $this->mob);		
		
		$this->db->where('address_id', $this->address_id);
		return $this->db->update('address');
	}

	public function delete($post) 
	{
		$this->db->where('address_id', $this->address_id);
		return $this->db->delete('address');
	}
	
	public function save($post) 
	{
		if (isset($this->address_id)) {	
			return $this->update($post);
		} else {
			return $this->insert($post);
		}
	}
}